package com.gzc.just.play.last.war.common.share.distributed;

import java.util.Map;

/**
 * Server instance information
 */
public class ServerInstance {
    
    /**
     * Instance ID (unique identifier)
     */
    private String instanceId;
    
    /**
     * Service name
     */
    private String serviceName;
    
    /**
     * Host address
     */
    private String host;
    
    /**
     * Port number
     */
    private int port;
    
    /**
     * Metadata information
     */
    private Map<String, String> metadata;
    
    /**
     * Registration time
     */
    private long registrationTime;
    
    public ServerInstance() {
    }
    
    public ServerInstance(String instanceId, String serviceName, String host, int port) {
        this.instanceId = instanceId;
        this.serviceName = serviceName;
        this.host = host;
        this.port = port;
        this.registrationTime = System.currentTimeMillis();
    }
    
    public ServerInstance(String instanceId, String serviceName, String host, int port, Map<String, String> metadata) {
        this.instanceId = instanceId;
        this.serviceName = serviceName;
        this.host = host;
        this.port = port;
        this.metadata = metadata;
        this.registrationTime = System.currentTimeMillis();
    }
    
    public String getInstanceId() {
        return instanceId;
    }
    
    public void setInstanceId(String instanceId) {
        this.instanceId = instanceId;
    }
    
    public String getServiceName() {
        return serviceName;
    }
    
    public void setServiceName(String serviceName) {
        this.serviceName = serviceName;
    }
    
    public String getHost() {
        return host;
    }
    
    public void setHost(String host) {
        this.host = host;
    }
    
    public int getPort() {
        return port;
    }
    
    public void setPort(int port) {
        this.port = port;
    }
    
    public Map<String, String> getMetadata() {
        return metadata;
    }
    
    public void setMetadata(Map<String, String> metadata) {
        this.metadata = metadata;
    }
    
    public long getRegistrationTime() {
        return registrationTime;
    }
    
    public void setRegistrationTime(long registrationTime) {
        this.registrationTime = registrationTime;
    }
    
    /**
     * Get service address
     */
    public String getAddress() {
        return host + ":" + port;
    }
    
    /**
     * Get service URI
     */
    public String getUri() {
        return "http://" + getAddress();
    }
}